<?php
include_once "com/code/Controller.php";
include_once "com/code/video/upload/UploadController.php";
include_once "com/code/video/contact/ContactController.php";

class VideoMenuController extends Controller {
	
	private $videoSearchEngineControllerId;
	private $uploadControllerId;
	
	public function __construct($params) {
		parent::__construct($params);
		
		$this->videoSearchEngineControllerId = Controller::newId("VideoSearchEngineController", $params);
		$this->uploadControllerId = Controller::newId("UploadController", $params);
	}
	
	public function desctruct() {
		if ($this->deleted()) {
			$uploadController = $this->getUploadController();
			if (!empty($uploadController)) {
				$uploadController->sessionDelete();
			}
			
			$videoSearchEngineController = $this->getVideoSearchEngineController();
			if (!empty($videoSearchEngineController)) {
				$videoSearchEngineController->sessionDelete();
			}
		}
		parent::__destruct();
	}
	
	public function getVideoSearchEngineController() {
		return Controller::getController("VideoSearchEngineController", $this->videoSearchEngineControllerId);
	}
	
	public function getUploadController() {
		return Controller::getController("UploadController", $this->uploadControllerId);
	}
	
	public function getVideoMenuView($params) {
		$view = new View("com/code/video/menu/VideoMenuView.php");
		$view->assignController($this);
		$vars = array();
		
		$videoSearchEngineController = $this->getVideoSearchEngineController();
		ob_start();
		$videoSearchEngineController->getSearchEngineView($params);
		$vars['videoSearchEngineView'] = ob_get_clean();
		
		$uploadController = $this->getUploadController();
		ob_start();
		$uploadController->getUploadView($params);
		$vars['uploadView'] = ob_get_clean();
		
		ob_start();
		ContactController::getContactView($params);
		$vars['contactView'] = ob_get_clean();
		
		$view->display($vars);
	}
	
	public function getVideoSearchEngineIdentifier($params) {
//		echo $this->videoSearchEngineControllerId;
		
		$videoSearchEngineController = $this->getVideoSearchEngineController();
		$id = $videoSearchEngineController->getControllerIdentifier();
		echo "(".json_encode($id).")";
	}
	
	public function getUploadIdentifier($params) {
		$uploadController = $this->getUploadController();
		$id = $uploadController->getControllerIdentifier();
		echo "(".json_encode($id).")";
	}
}
?>